package com.kerbores.aeasy.framwork.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import android.content.Context;

public class DBUtils {

	public static void initDao(Context context, String dbName) {
		Connection conn = null;
		String filePath = context.getDatabasePath(dbName).getPath();
		try {
//			Class.forName("org.sqlite.JDBC");
//			String url = "jdbc:sqldroid:" + getDataPath() + "/main.sqlite";
			 conn = DriverManager.getConnection("jdbc:sqldroid:" + filePath);
//			conn = DriverManager.getConnection("jdbc:sqlite:/" + filePath);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			PreparedStatement pstmt = conn.prepareStatement("select * from aczy_customer");
			ResultSet rs = pstmt.executeQuery();
			int rows = rs.getMetaData().getColumnCount();
			while (rs.next()) {
				for (int i = 0; i < rows; i++) {
					System.out.println(rs.getObject(i));
				}
			}
		} catch (SQLException e1) {
			e1.printStackTrace();
		}

//		SimpleDataSource dataSource = new SimpleDataSource();
//		try {
//			dataSource.setDriverClassName("org.sqlite.JDBC");
//		} catch (ClassNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		dataSource.setJdbcUrl("jdbc:sqlite:" + filePath);
//		System.out.println(new File(filePath).exists());
//		return new NutDao(dataSource);
	}
}
